# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2025/3/1
desc: 
sample: 
"""
data1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  # list  #更改
data1.append(11)
print(type(data1))
data2 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)  # tuple #不能更改
print(type(data2))
data3 = {1, 2, 10, 10, 10}  # set  重复性问题
print(type(data3))
print(data3)

print("获取list set tuple 循环方式 ")
for i in data3:
    print(i)

print("获取下标 ")
print(data1[0])

data4 = {
    'name': '张三',
    'age': 18,
    'sex': '男'
}
print('字典获取方式')
print(data4['name'])
print(data4.get('name'))
print(data4.get('111'))

# 嵌套
print(data4.items())

for item in data4.items():
    print(item[0], item[1])

for k, v in data4.items():
    print(k, v)

# 集合的操作案例
#需求: 过滤未开启的测试用例，根据order排序
test = [{'caseName': '测试1', 'order': 2, '开启': '是'},
        {'caseName': '测试2','order': 1, '开启': '是'},
        {'caseName': '测试3', 'order': 4, '开启': '否'},
        {'caseName': '测试4','order': 3, '开启': '是'}]
#第一种常规过滤方法
new_test=[]
new_test=list()
for i in test:
    if i['开启']=='是':
        new_test.append(i)
print(new_test)
#第二种 用推导式
new_test=[case for case in test if case.get('开启')=='是']
print(new_test)
#下一步根据order排序

def takeOrder(elem):
   return elem["order"]

new_test2=list(sorted(new_test,key=takeOrder,reverse=True))
print(new_test2)

#lambda
new_test3= list(sorted(new_test,key=lambda i:i["order"],reverse=True))
print(new_test3)

